﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SQLite;
using System.Collections;
using NHibernate;
using OBSwindles;

namespace DASwindles
{
    public class LoanData : IDataManager
    {
        public LoanData()
        {
            
        }
        #region IDataManager Members

        public IList getDetails()
        {
            IList loanList = null;
            ISession session = DAHelper.getSession();
            loanList = session.CreateCriteria(typeof(LoanInfo)).List();
            return loanList;
        }

        public object getDetails_ByID(int p_ID)
        {
            IList loanList = null;
            ISession session = DAHelper.getSession();
            loanList = session.CreateCriteria(typeof(LoanInfo)).List();
            if (loanList != null)
            {
                for (int i = 0; i < loanList.Count; i++)
                {
                    LoanInfo loanInfo = (LoanInfo)loanList[i];
                    if (loanInfo.LoanID == p_ID)
                    {
                        return loanInfo;
                    }
                }

            }
            return null;
        }

        public void updateDetails(object p_Object)
        {
            ISession session = DAHelper.getSession();
            session.Update(p_Object);
        }

        public int insertDetails(object p_Object)
        {
            ISession session = DAHelper.getSession();
            session.Save(p_Object);
            return ((LoanInfo)p_Object).LoanID;
        }

        #endregion
    }
}